-------------------------
-- KURALAK THE DEFILER --
-------------------------
local Locales = {
	["Kuralak the Defiler"] = {
		[1] = "Kuralak the Defiler",
		[2] = "Kuralak die Schänderin",
		[3] = "Kuralak le Profanateur",
	},
	["Cultivate Corruption"] = { --60446
		[1] = "Cultivate Corruption",
		[2] = "Korrumpierung kultivieren",
		[3] = "Nourrir la corruption",
	},
	["Chromosome Corruption"] = { --56652
		[1] = "Chromosome Corruption",
		[2] = "Chromosomen-Korrumpierung",
		[3] = "Corruption chromosomique",
	},
	["Outbreak"] = { --60623
		[1] = "Outbreak",
		[2] = "Ausbruch",
		[3] = "Invasion",
	},
	["Vanish into Darkness"] = { --60121
		[1] = "Vanish into Darkness",
		[2] = "In der Dunkelheit verschwinden",
		[3] = "Disparaître dans les ténèbres",
	},
	["GO TO YOUR PILLARS!!!"] = {
		[1] = "GO TO YOUR PILLARS!!!",
		[2] = "An eure Säule rennen!",
		[3] = "A VOS PILLIERS!!!",
	},
}

local function GAKuralak(tUnits)
	local currTime = GameLib.GetGameTime()
	for unitid, unitdata in pairs(tUnits) do
		local unitname = unitdata.unit:GetName()
		if unitname == Raiderino.L["Kuralak the Defiler"] then
			local castname = Raiderino:GetCast(unitid,unitdata.unit)
			if castname then
				if castname == Raiderino.L["Cultivate Corruption"] then
					if Raiderino:FeatureCheck("Kuralak the Defiler","Cultivate Corruption") then
						local msg = {text = "Cultivate Corruption", maxtime = 65, icon = nil, destroyAtEnd = false}
						Raiderino.timers:AddTimer(msg)
					end
				elseif castname == Raiderino.L["Chromosome Corruption"] then
					if Raiderino:FeatureCheck("Kuralak the Defiler","Cultivate Corruption") then
						local msg = {text = "Cultivate Corruption", maxtime = 65, icon = nil, destroyAtEnd = false}
						Raiderino.timers:AddTimer(msg)
					end
				elseif castname == Raiderino.L["Outbreak"] then
					if Raiderino:FeatureCheck("Kuralak the Defiler","Outbreak") then
						local msg = {text = "Outbreak", maxtime = 45, icon = nil, destroyAtEnd = false}
						Raiderino.timers:AddTimer(msg)
					end
				elseif castname == Raiderino.L["Vanish into Darkness"] then
					if Raiderino:FeatureCheck("Kuralak the Defiler","Vanish into Darkness") then
						local msg = {}
						local timetillstart = currTime - Raiderino.nFightStartTime
						if timetillstart < 50 then
							msg = {text = "Vanish into Darkness", maxtime = 50, icon = nil, destroyAtEnd = true}
						elseif timetillstart < 105 then
							msg = {text = "Vanish into Darkness", maxtime = 55, icon = nil, destroyAtEnd = true}
						elseif timetillstart > 105 then
							msg = {text = "Vanish into Darkness", maxtime = 60, icon = nil, destroyAtEnd = true}
						end
						Raiderino.timers:AddTimer(msg)
					end
				else
					Raiderino:UntimedCastAdd(unitname,castname)
				end
			end
			
			if not Raiderino:GetPhase("Kuralak the Defiler") == 2 and Raiderino:GetHealthPercent(unitdata.unit) < 72 then
				Raiderino:PhaseSwitch("Kuralak the Defiler",2)
			end
		end
	end

	if Raiderino:FeatureCheck("Kuralak the Defiler","GO TO YOUR PILLARS!!!") then
		if Raiderino.timers.content["Vanish into Darkness"] and not Raiderino.timers.content["Vanish into Darkness"].notified then
			if Raiderino.timers.content["Vanish into Darkness"].EndTime - currTime < 8 and not Raiderino.notifications.content["GO TO YOUR PILLARS!!!"] then
				local msg = {text = "GO TO YOUR PILLARS!!!", maxtime = 10, icon = nil, destroyAtEnd = true}
				Raiderino.notifications:AddTimer(msg)
				Raiderino.timers.content["Vanish into Darkness"].notified = true
			end
		end
	end
end

local function PhaseKuralak(phase)
	if phase == 2 then
		if Raiderino.timers.content["Vanish into Darkness"] then
			Raiderino.timers.content["Vanish into Darkness"].Frame:Destroy()
			Raiderino.timers.content["Vanish into Darkness"] = nil
		end
		if Raiderino.notifications.content["GO TO YOUR PILLARS!!!"] then
			Raiderino.notifications.content["GO TO YOUR PILLARS!!!"].Frame:Destroy()
			Raiderino.notifications.content["GO TO YOUR PILLARS!!!"] = nil
		end
	end
end

local function StartKuralak()

end
--------------------------
-- /KURALAK THE DEFILER --
--------------------------

local encounteroptions = {
	enabled = true,
	position = 2,
	zone = "Genetic Archives - Act 1",
	fBossFunction = GAKuralak,
	fPhaseFunction = PhaseKuralak,
	fOnStartCombat = nil,
	features = {
		["Cultivate Corruption"] = {
			displayname = "Cultivate Corruption",
			enabled = true
		},
		["Outbreak"] = {
			displayname = "Outbreak",
			enabled = true
		},
		["Vanish into Darkness"] = {
			displayname = "Vanish into Darkness",
			enabled = true
		},
		["GO TO YOUR PILLARS!!!"] = {
			displayname = "GO TO YOUR PILLARS!!!",
			enabled = true
		},
	},
}

if _G["RaiderinoLibs"] == nil then
	_G["RaiderinoLibs"] = { }
end
if _G["RaiderinoLibs"]["Encounters"] == nil then
	_G["RaiderinoLibs"]["Encounters"] = { }
end

_G["RaiderinoLibs"]["Encounters"]["Kuralak the Defiler"] = encounteroptions

if _G["RaiderinoLibs"]["Locales"] == nil then
	_G["RaiderinoLibs"]["Locales"] = { }
end
for locale, localedata in pairs(Locales) do
	if not RaiderinoLibs.Locales[locale] then
		RaiderinoLibs.Locales[locale] = {}
		for i,localestring in pairs(localedata) do
			RaiderinoLibs.Locales[locale][i] = localestring
		end
	end
end